#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Experimental/Commodities/DateInterval.h>
#pragma unmanaged 
#include <ql\experimental\commodities\pricingperiod.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

#undef HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Experimental { namespace Commodities {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IPricingPeriod
	public ref class CPricingPeriod  : 
            public CDateInterval,
            public Cephei::QL::Experimental::Commodities::IPricingPeriod
	{
	protected: 
		boost::shared_ptr<QuantLib::PricingPeriod>* _ppPricingPeriod;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::PricingPeriod>* _phPricingPeriod;
#endif
		Object^ _PricingPeriodOwner;     // reference to object that manages the storage for this object
	internal:
		CPricingPeriod (DateTime startDate, DateTime endDate, DateTime paymentDate, Cephei::QL::Experimental::Commodities::IQuantity^ quantity);
        CPricingPeriod (boost::shared_ptr<QuantLib::PricingPeriod>& childNative, Object^ owner);
        CPricingPeriod (QuantLib::PricingPeriod& childNative, Object^ owner);
        CPricingPeriod (CPricingPeriod^ copy);
        CPricingPeriod (PLATFORM::Type^ t);
#ifdef STRUCT
        CPricingPeriod (QuantLib::PricingPeriod childNative);
#endif       
#ifdef HANDLE
		CPricingPeriod (QuantLib::Handle<QuantLib::PricingPeriod>& childNative, Object^ owner);
		CPricingPeriod (QuantLib::Handle<QuantLib::PricingPeriod> childNative);
#endif
		virtual ~CPricingPeriod ();
		!CPricingPeriod ();

	internal:
		QuantLib::PricingPeriod& GetReference ();
		boost::shared_ptr<QuantLib::PricingPeriod>& GetShared ();
		QuantLib::PricingPeriod* GetPointer ();
        void SetPricingPeriod (boost::shared_ptr<QuantLib::PricingPeriod> native)
        {
            if (_ppPricingPeriod != NULL)
                delete _ppPricingPeriod;
            _ppPricingPeriod = new boost::shared_ptr<QuantLib::PricingPeriod> (native);
            SetDateInterval (boost::dynamic_pointer_cast<QuantLib::DateInterval> (*_ppPricingPeriod));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::PricingPeriod>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property DateTime PaymentDate 
        {
		    virtual DateTime get () ;
        }
        property Cephei::QL::Experimental::Commodities::IQuantity^ Quantity 
        {
		    virtual Cephei::QL::Experimental::Commodities::IQuantity^ get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IPricingPeriod Vector interface
	ref class CPricingPeriodVector sealed : 
							    public Core::INativeVector<IPricingPeriod^>,
							    public Core::INativeVector<Core::Generic::ICoCell<IPricingPeriod^>^>
	{
	private:
#ifdef STRUCT
		std::vector<QuantLib::PricingPeriod>* _pVValue;
#endif        
		std::vector<boost::shared_ptr<QuantLib::PricingPeriod>>* _pVBoost;
#ifdef HANDLE
		std::vector<QuantLib::Handle<QuantLib::PricingPeriod>>* _pVHand;
#endif
		Object^ _owner;		// object reference to prevent GC of vector owner

	internal:
		CPricingPeriodVector ();
#ifdef STRUCT
		CPricingPeriodVector (std::vector<QuantLib::PricingPeriod>& vec, Object^ owner);
		CPricingPeriodVector (std::vector<QuantLib::PricingPeriod> vec);
#endif       
		CPricingPeriodVector (std::vector<boost::shared_ptr<QuantLib::PricingPeriod>>& vec, Object^ owner);
#ifdef HANDLE
		CPricingPeriodVector (std::vector<QuantLib::Handle<QuantLib::PricingPeriod>>& vec, Object^ owner);
#endif
		virtual ~CPricingPeriodVector ();
		!CPricingPeriodVector ();

    public:
		property int Count 
		{
			virtual int get ();
		}

		property IPricingPeriod^ default[int] 
		{
			virtual IPricingPeriod^ get (int index) = Core::INativeVector<IPricingPeriod^>::default::get;
			virtual void set (int index, IPricingPeriod^ value) = Core::INativeVector<IPricingPeriod^>::default::set;
		}

		//////////////////////////////////////////////////////////////////////////////////////////
		// Interface functions for cell vectors 
	public:
		property Core::Generic::ICoCell<Cephei::QL::Experimental::Commodities::IPricingPeriod^>^ CItem[int] 
		{
			virtual Core::Generic::ICoCell<IPricingPeriod^>^ get (int index) = Core::INativeVector<Core::Generic::ICoCell<IPricingPeriod^>^>::default::get;
			virtual void set (int index, Core::Generic::ICoCell<IPricingPeriod^>^ value) = Core::INativeVector<Core::Generic::ICoCell<IPricingPeriod^>^>::default::set;
		}
	internal:
#ifdef STRUCT    
		std::vector<QuantLib::PricingPeriod>& GetReference ();
#endif     
		std::vector<boost::shared_ptr<QuantLib::PricingPeriod>>& GetShared ();

#ifdef HANDLE
		std::vector<QuantLib::Handle<QuantLib::PricingPeriod>>& GetHandle ();
#endif
	public:
		virtual bool PrepareFeature (NativeFeature feature);
	};
    
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::Experimental::Commodities::IPricingPeriod^>::typeid)]
	[FactoryFor(Cephei::QL::Experimental::Commodities::IPricingPeriod::typeid)]
	[FactoryFor(Cephei::QL::Experimental::Commodities::IPricingPeriod_Factory::typeid)]
	public ref class CPricingPeriod_Factory sealed : public IPricingPeriod_Factory
	{
	public:
        virtual IPricingPeriod^ Create (DateTime startDate, DateTime endDate, DateTime paymentDate, Cephei::QL::Experimental::Commodities::IQuantity^ quantity);
        /* <summary> Create a hybrid Vector of IPricingPeriod, with event notification of changes </summary> */
        virtual Cephei::Core::IVector<IPricingPeriod^>^ CreateVector();
        /* <summary> Create a hybrid Vector of ICell of IPricingPeriod, with event notification of changes </summary> */
        virtual Core::Generic::ICoCell<Cephei::Core::IVector<Core::Generic::ICoCell<IPricingPeriod^>^>^>^ CreateCellVector();
        virtual Cephei::Core::IVector<IPricingPeriod^>^ CreateVector(PLATFORM::Collections::Generic::IEnumerable<IPricingPeriod^>^ source);
        virtual Core::Generic::ICoCell<Cephei::Core::IVector<Core::Generic::ICoCell<IPricingPeriod^>^>^>^ CreateCellVector(PLATFORM::Collections::Generic::IEnumerable<Core::Generic::ICoCell<IPricingPeriod^>^>^ source);
		virtual Core::INativeVector<Cephei::QL::Experimental::Commodities::IPricingPeriod^>^ CreateNativeVector ()
		{
			return REFNEW CPricingPeriodVector ();
		}

        virtual Core::INativeMatrix<Cephei::QL::Experimental::Commodities::IPricingPeriod^>^ CreateNativeMatrix ()
		{
			return nullptr;
		}

        virtual Core::INativeCube<Cephei::QL::Experimental::Commodities::IPricingPeriod^>^ CreateNativeCube ()
		{
			return nullptr;
		}
    };
   
/*Cephei*/ } /*QL*/ } /*Experimental*/ } /*Commodities */}
